package com.sky.config;

import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author liudo
 * @version 1.0
 * @project sky-take-out
 * @date 2023/12/8 10:48:12
 */
@Configuration
public class RedisConfiguration {
    // string  list  hashMap  -慢 可读性差 占用资源  - json
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);
        // 序列化相关的配置
        template.setKeySerializer(new StringRedisSerializer());
        template.setDefaultSerializer(new GenericFastJsonRedisSerializer());
        return template;
    }
}
